//
//  QCSystemSettingController.swift
//  爱汽车
//
//  Created by liujianlong on 2023/8/24.
//

import UIKit

class QCSystemSettingController: QCViewController {
    //var array = ["气罐压力","工作模式","高度尺工具","电瓶保护","点火熄火设置","高度记忆设置","维修模式","最低行驶保护气压"]
    //    var array = ["气罐压力","高度尺工具","电瓶保护","点火熄火设置","高度记忆设置","维修模式","最低行驶保护气压","气压平衡"]
    var array = ["气罐压力","记忆模式","电瓶保护","点火熄火设置","高度记忆设置","维修模式","最低行驶保护气压"]
    override func viewDidLoad() {
        super.viewDidLoad()
        initUI()
    }
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        updateUI()
    }
    override func initUI() {
        title = LS("系统设置")
        tableView.delegate = self
        tableView.dataSource = self
        tableView.register(QCSettingCell.nib(), forCellReuseIdentifier: QCSettingCell.ID())
        tableView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        updateUI()
    }
    
    
    func updateUI(){
        guard let mode = deviceMode else{return}
        switch mode {
        case DeviceMode.supportHeightPressure:
            switch isPressureMode {
            case true:
                array = ["气罐压力","记忆模式","电瓶保护","点火熄火设置","高度记忆设置","维修模式","最低行驶保护气压"]
            case false:
                array = ["气罐压力","记忆模式","高度尺工具","电瓶保护","点火熄火设置","高度记忆设置","维修模式","最低行驶保护气压","气压平衡"]
            }
        case DeviceMode.supportPressure:
            array = ["气罐压力","电瓶保护","点火熄火设置","高度记忆设置","维修模式","最低行驶保护气压"]
        }
        tableView.reloadData()
    }
}
//MARK: - UITableViewDataSource
extension QCSystemSettingController:UITableViewDataSource
{
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return array.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: QCSettingCell.ID()) as! QCSettingCell
        cell.img.image = UIImage(named: array[indexPath.row])
        cell.title.text = LS(array[indexPath.row])
        return cell
    }
}
//MARK: - UITableViewDelegate
extension QCSystemSettingController:UITableViewDelegate{
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        switch array[indexPath.row]{
        case "气罐压力":
            push(QCAirPressionController(),true)
        case "工作模式":
            push(QCWorkController(),true)
        case "记忆模式":
            let vc = QCRemeberController()
            vc.block = {[weak self] ispressure in
                isPressureMode = ispressure
                self?.updateUI()
            }
            push(vc,true)
        case "高度尺工具":
            push(QCRulerController(),true)
        case "电瓶保护":
            push(QCProtectController(),true)
        case "点火熄火设置":
            push(QCFireController(),true)
        case "高度记忆设置":
            push(QCHeightController(),true)
        case "维修模式":
            push(QCFixViewController(),true)
        case "最低行驶保护气压":
            push(QCDrivingController(),true)
        case "气压平衡":
            push(QCAutoBalanceController(),true)
        default:
            break
        }
    }
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 0
    }
    
    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 0
    }
    
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        return nil
    }
    
    func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
        return nil
    }
}
